/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Farcast;

import javax.microedition.lcdui.*;

/**
 *
 * @author Jeroen Rikhof
 */
public class FormMain extends Form implements CommandListener, ItemCommandListener {
    private Farcast midlet;
    private Command cmdExit;
    private Command cmdEdit;
    
    private StringItem txtTitle;
    private StringItem txtText;
    
    public EditTxtForm editform;
    
    public FormMain(Farcast midlet) {
        super("Farcast Message");
        this.midlet = midlet;
        
        cmdEdit = new Command("Edit", Command.OK, 1);
        cmdExit = new Command("Exit", Command.EXIT, 0);
        
        txtTitle = new StringItem("Title", midlet.message.getMessageTitle());
        txtText= new StringItem("Text", midlet.message.getMessageBody());
        
        append(txtTitle);
        append(txtText);
        
        txtTitle.addCommand(cmdEdit);
        txtTitle.setItemCommandListener(this);
        txtText.addCommand(cmdEdit);
        txtText.setItemCommandListener(this);

        addCommand(cmdExit);
        setCommandListener(this);
    }
    
    public void commandAction (Command c, Displayable d){
        if (c == cmdExit){
            this.midlet.exitMIDlet();            
        }
    }
    
    public void commandAction (Command c, Item i){
        if (c == cmdEdit){
            if (i == txtText){
                try {
                    midlet.displayManager.pushDisplayable(new EditTxtForm(midlet, "Text"));
                } catch (Exception e) {
                    System.out.println(e);
                }
                
            }
            if (i == txtTitle){
                try {
                    midlet.displayManager.pushDisplayable(new EditTxtForm(midlet, "Title"));
                } catch (Exception e) {
                    System.out.println(e);
                }
            }
            
        }
    }
   
}
